nlp_architect.models.ner_crf.NERCRF

class nlp_architect.models.ner_crf.NERCRF(use_cudnn=False)[source]

Bi-LSTM NER model with CRF classification layer (tf.keras model)

Parameters

use_cudnn (bool, optional) – use cudnn LSTM cells

__init__(use_cudnn=False)[source]

Initialize self. See help(type(self)) for accurate signature.

Methods

__init__([use_cudnn])

Initialize self.

build(word_length, target_label_dims, …[, …])

Build a NERCRF model

fit(x, y[, epochs, batch_size, callbacks, …])

Train a model given input samples and target labels.

load(path)

Load model weights

load_embedding_weights(weights)

Load word embedding weights into the model embedding layer

predict(x[, batch_size])

Get the prediction of the model on given input

save(path)

Save model to path

build(word_length, target_label_dims, word_vocab_size, char_vocab_size, word_embedding_dims=100, char_embedding_dims=16, tagger_lstm_dims=200, dropout=0.5)[source]

Build a NERCRF model

Parameters
  • word_length (int) – max word length in characters

  • target_label_dims (int) – number of entity labels (for classification)

  • word_vocab_size (int) – word vocabulary size

  • char_vocab_size (int) – character vocabulary size

  • word_embedding_dims (int) – word embedding dimensions

  • char_embedding_dims (int) – character embedding dimensions

  • tagger_lstm_dims (int) – word tagger LSTM output dimensions

  • dropout (float) – dropout rate

fit(x, y, epochs=1, batch_size=1, callbacks=None, validation=None)[source]

Train a model given input samples and target labels.

Parameters
  • x (numpy.ndarray or numpy.ndarray) – input samples

  • y (numpy.ndarray) – input sample labels

  • epochs (int, optional) – number of epochs to train

  • batch_size (int, optional) – batch size

  • callbacks (Callback, optional) – Keras compatible callbacks

  • validation (list of numpy.ndarray, optional) – optional validation data to be evaluated when training

load(path)[source]

Load model weights

Parameters

path (str) – path to load model from

load_embedding_weights(weights)[source]

Load word embedding weights into the model embedding layer

Parameters

weights (numpy.ndarray) – 2D matrix of word weights

predict(x, batch_size=1)[source]

Get the prediction of the model on given input

Parameters
  • x (numpy.ndarray or numpy.ndarray) – input samples

  • batch_size (int, optional) – batch size

Returns

predicted values by the model

Return type

numpy.ndarray

save(path)[source]

Save model to path

Parameters

path (str) – path to save model weights